<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入公司名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司手机" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入公司手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入公司电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="addressDetail">
        <el-input
          v-model="queryParams.addressDetail"
          placeholder="请输入详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人姓名" prop="linkmanName">
        <el-input
          v-model="queryParams.linkmanName"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人QQ" prop="linkmanQq">
        <el-input
          v-model="queryParams.linkmanQq"
          placeholder="请输入联系人QQ"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人电话" prop="linkmanMobile">
        <el-input
          v-model="queryParams.linkmanMobile"
          placeholder="请输入联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人EMAIL" prop="linkmanEmail">
        <el-input
          v-model="queryParams.linkmanEmail"
          placeholder="请输入联系人EMAIL"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照号" prop="licenseNumber">
        <el-input
          v-model="queryParams.licenseNumber"
          placeholder="请输入营业执照号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税务登记证号" prop="taxNumber">
        <el-input
          v-model="queryParams.taxNumber"
          placeholder="请输入税务登记证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织机构代码" prop="orgNumber">
        <el-input
          v-model="queryParams.orgNumber"
          placeholder="请输入组织机构代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入公司地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司LOGO图" prop="logoPic">
        <el-input
          v-model="queryParams.logoPic"
          placeholder="请输入公司LOGO图"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人" prop="legalPerson">
        <el-input
          v-model="queryParams.legalPerson"
          placeholder="请输入法定代表人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法定代表人身份证" prop="legalPersonCardId">
        <el-input
          v-model="queryParams.legalPersonCardId"
          placeholder="请输入法定代表人身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户行账号名称" prop="bankUser">
        <el-input
          v-model="queryParams.bankUser"
          placeholder="请输入开户行账号名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户行" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入开户行"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manager:seller:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manager:seller:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manager:seller:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manager:seller:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sellerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="sellerId" />
      <el-table-column label="公司名" align="center" prop="name" />
      <el-table-column label="店铺名称" align="center" prop="nickName" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="EMAIL" align="center" prop="email" />
      <el-table-column label="公司手机" align="center" prop="mobile" />
      <el-table-column label="公司电话" align="center" prop="telephone" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="详细地址" align="center" prop="addressDetail" />
      <el-table-column label="联系人姓名" align="center" prop="linkmanName" />
      <el-table-column label="联系人QQ" align="center" prop="linkmanQq" />
      <el-table-column label="联系人电话" align="center" prop="linkmanMobile" />
      <el-table-column label="联系人EMAIL" align="center" prop="linkmanEmail" />
      <el-table-column label="营业执照号" align="center" prop="licenseNumber" />
      <el-table-column label="税务登记证号" align="center" prop="taxNumber" />
      <el-table-column label="组织机构代码" align="center" prop="orgNumber" />
      <el-table-column label="公司地址" align="center" prop="address" />
      <el-table-column label="公司LOGO图" align="center" prop="logoPic" />
      <el-table-column label="简介" align="center" prop="brief" />
      <el-table-column label="法定代表人" align="center" prop="legalPerson" />
      <el-table-column label="法定代表人身份证" align="center" prop="legalPersonCardId" />
      <el-table-column label="开户行账号名称" align="center" prop="bankUser" />
      <el-table-column label="开户行" align="center" prop="bankName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manager:seller:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manager:seller:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商家审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司名" prop="name">
          <el-input v-model="form.name" placeholder="请输入公司名" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入店铺名称" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="EMAIL" prop="email">
          <el-input v-model="form.email" placeholder="请输入EMAIL" />
        </el-form-item>
        <el-form-item label="公司手机" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入公司手机" />
        </el-form-item>
        <el-form-item label="公司电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入公司电话" />
        </el-form-item>
        <el-form-item label="详细地址" prop="addressDetail">
          <el-input v-model="form.addressDetail" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="linkmanName">
          <el-input v-model="form.linkmanName" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="联系人QQ" prop="linkmanQq">
          <el-input v-model="form.linkmanQq" placeholder="请输入联系人QQ" />
        </el-form-item>
        <el-form-item label="联系人电话" prop="linkmanMobile">
          <el-input v-model="form.linkmanMobile" placeholder="请输入联系人电话" />
        </el-form-item>
        <el-form-item label="联系人EMAIL" prop="linkmanEmail">
          <el-input v-model="form.linkmanEmail" placeholder="请输入联系人EMAIL" />
        </el-form-item>
        <el-form-item label="营业执照号" prop="licenseNumber">
          <el-input v-model="form.licenseNumber" placeholder="请输入营业执照号" />
        </el-form-item>
        <el-form-item label="税务登记证号" prop="taxNumber">
          <el-input v-model="form.taxNumber" placeholder="请输入税务登记证号" />
        </el-form-item>
        <el-form-item label="组织机构代码" prop="orgNumber">
          <el-input v-model="form.orgNumber" placeholder="请输入组织机构代码" />
        </el-form-item>
        <el-form-item label="公司地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入公司地址" />
        </el-form-item>
        <el-form-item label="公司LOGO图" prop="logoPic">
          <el-input v-model="form.logoPic" placeholder="请输入公司LOGO图" />
        </el-form-item>
        <el-form-item label="简介" prop="brief">
          <el-input v-model="form.brief" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="法定代表人" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入法定代表人" />
        </el-form-item>
        <el-form-item label="法定代表人身份证" prop="legalPersonCardId">
          <el-input v-model="form.legalPersonCardId" placeholder="请输入法定代表人身份证" />
        </el-form-item>
        <el-form-item label="开户行账号名称" prop="bankUser">
          <el-input v-model="form.bankUser" placeholder="请输入开户行账号名称" />
        </el-form-item>
        <el-form-item label="开户行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户行" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSeller, getSeller, delSeller, addSeller, updateSeller } from "@/api/manager/seller";

export default {
  name: "Seller",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商家审核表格数据
      sellerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        nickName: null,
        mobile: null,
        telephone: null,
        status: null,
        addressDetail: null,
        linkmanName: null,
        linkmanQq: null,
        linkmanMobile: null,
        linkmanEmail: null,
        licenseNumber: null,
        taxNumber: null,
        orgNumber: null,
        address: null,
        logoPic: null,
        brief: null,
        legalPerson: null,
        legalPersonCardId: null,
        bankUser: null,
        bankName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商家审核列表 */
    getList() {
      this.loading = true;
      listSeller(this.queryParams).then(response => {
        this.sellerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sellerId: null,
        name: null,
        nickName: null,
        password: null,
        email: null,
        mobile: null,
        telephone: null,
        status: "0",
        addressDetail: null,
        linkmanName: null,
        linkmanQq: null,
        linkmanMobile: null,
        linkmanEmail: null,
        licenseNumber: null,
        taxNumber: null,
        orgNumber: null,
        address: null,
        logoPic: null,
        brief: null,
        createTime: null,
        legalPerson: null,
        legalPersonCardId: null,
        bankUser: null,
        bankName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sellerId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商家审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sellerId = row.sellerId || this.ids
      getSeller(sellerId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商家审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sellerId != null) {
            updateSeller(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSeller(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sellerIds = row.sellerId || this.ids;
      this.$modal.confirm('是否确认删除商家审核编号为"' + sellerIds + '"的数据项？').then(function() {
        return delSeller(sellerIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manager/seller/export', {
        ...this.queryParams
      }, `seller_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
